import 'dart:math';

import 'package:mvvm_demo/mvvm/mutable_live_data.dart';
import 'package:mvvm_demo/mvvm/top_data.dart';

import 'list_data.dart';

class ViewModel {
  late TopData topData;
  late ListData listData;
  late MutableLiveData<String> text;

  ViewModel() {
    topData = TopData();
    listData = ListData();
    text = MutableLiveData("");
  }

  void refreshData() {
    //此处是数据请求，简单模拟一下
    int num = Random().nextInt(100);
    topData.setData("张三$num", num.toString());
    text.postValue("liveData$num");
  }

  void refreshList() {
    //数据请求，模拟一下
    var list = <String>[];
    for (var i = 0; i < 5; i++) {
      int num = Random().nextInt(10);
      list.add("Item$num");
    }
    listData.setList(list);
  }
}
